package com.lsb.fitnessnutrition

import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.ArrayAdapter
import androidx.annotation.RequiresApi
import kotlinx.android.synthetic.main.activity_list_plan.*
import kotlinx.android.synthetic.main.activity_list_power.*
import org.tensorflow.lite.examples.classification.R

class ListPowerActivity : AppCompatActivity() {
    @RequiresApi(Build.VERSION_CODES.P)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_list_power)

        //连接数据库
        val dbHelper=MyDatabaseHelper(this,"PowerStore.db",null,1)
        val db: SQLiteDatabase
        db=dbHelper.writableDatabase

        val cursor: Cursor
        //查询power表
        cursor=db.query("power",null,null,
            null,null,null,null,null)

        var list=ArrayList<String>()
        if(cursor.moveToFirst()){
            do {
                var str_1:String=cursor.getString(cursor.getColumnIndex("type"))
                var str_2:String=cursor.getString(cursor.getColumnIndex("rm"))
                var str:String=str_1+"  :  "+str_2+"kg"
                list.add(str)
            }while (cursor.moveToNext())
        }
        cursor.close()
        var adapter= ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1,list)
        list_view_power.setAdapter(adapter);

    }
}